package com.futures.investm.fragment;

import android.os.Bundle;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.futures.investm.R;
import com.futures.investm.adapter.MarketOilAdapter;
import com.futures.investm.constant.Api;
import com.futures.investm.entity.MarketInfo;
import com.futures.investm.utils.ListToStringUtil;
import com.vise.xsnow.http.ViseHttp;
import com.vise.xsnow.http.callback.ACallback;
import com.vise.xsnow.http.request.GetRequest;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import butterknife.BindView;
import tech.com.commoncore.base.BaseFragment;
import tech.com.commoncore.entity.BaseTResp;

/**
 * 行情--》原油
 */
public class OilMarketFragment extends BaseFragment {
    @BindView(R.id.rv)
    RecyclerView rv_oil;//原油


    //原油
    MarketOilAdapter mMarketOilAdapter;


    public static OilMarketFragment newInstance() {
        Bundle args = new Bundle();
        OilMarketFragment fragment = new OilMarketFragment();
        fragment.setArguments(args);
        return fragment;
    }


    @Override
    public int getContentLayout() {
        return R.layout.fragment_market_to_market;
    }

    @Override
    public void initView(Bundle savedInstanceState) {

        //原油
        rv_oil.setLayoutManager(new LinearLayoutManager(mContext));
        mMarketOilAdapter = new MarketOilAdapter();
        getOil();
        rv_oil.setAdapter(mMarketOilAdapter);
        rv_oil.addItemDecoration(new DividerItemDecoration(mContext,DividerItemDecoration.VERTICAL));

    }

    /**
     * 原油
     */
    private void getOil() {
        //获取需要请求的原油参数
        List<String> list = Arrays.asList(mContext.getResources().getStringArray(R.array.OilParam));

        GetRequest request = ViseHttp.GET(Api.MARKET_URL)
                .addParam("symbol", ListToStringUtil.listToString(list))
                .addParam("type", "5");
        request.request(new ACallback<BaseTResp<ArrayList<MarketInfo>>>() {
            @Override
            public void onSuccess(BaseTResp<ArrayList<MarketInfo>> data) {

                mMarketOilAdapter.setNewData(data.data);

            }

            @Override
            public void onFail(int errCode, String errMsg) {
            }
        });
    }


}
